package com.controller;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.jws.WebParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.FileUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bean.About;
import com.bean.Admin;
import com.bean.Application;
import com.bean.CaseList;
import com.bean.Honor;
import com.bean.IndexImg;
import com.bean.JiShu;
import com.bean.RenLi;
import com.bean.SecondTitle;
import com.bean.Title;
import com.bean.TouZhi;
import com.bean.XiaZai;
import com.bean.XinWen;
import com.bean.XuQiu;
import com.bean.ZhaoPin;
import com.biz.AboutService;
import com.biz.AdminService;
import com.biz.ApplicationService;
import com.biz.CaseListService;
import com.biz.HonorService;
import com.biz.IndexImgService;
import com.biz.JiShuService;
import com.biz.RenLiService;
import com.biz.SecondTitleService;
import com.biz.TitleService;
import com.biz.TouZhiService;
import com.biz.XiaZaiService;
import com.biz.XinWenService;
import com.biz.XuQiuService;
import com.biz.ZhaoPinService;
import com.util.MyPagination;
import com.util.WebUtil;

@Controller
@RequestMapping(value = "/front")
@Scope("prototype")
public class frontcontroller {
	@Resource
	private AboutService aboutService;

	@Resource
	private ApplicationService appService;

	@Resource
	private XinWenService xinwenService;

	@Resource
	private XuQiuService xuQiuService;

	@Resource
	private TouZhiService touZhiService;

	@Resource
	private ZhaoPinService zhaoPinService;

	@Resource
	private RenLiService renliService;

	@Resource
	private JiShuService jiShuService;
	
	@Resource
	private HonorService honorService;

	@Resource
	private CaseListService caseListService;
	
	@Resource
	private XiaZaiService xiaZaiService;
	
	@Resource
	private TitleService titleService;
	
	@Resource
	private SecondTitleService secondTitleService;
	
	@Resource
	private IndexImgService imgService;
	
	MyPagination page = new MyPagination();
	
	@RequestMapping("/top")
	public String top(Model model,HttpServletRequest request,HttpServletResponse response){

		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id order by sort asc ", 1);
		model.addAttribute("second", secList);
		System.out.println("first:"+title);
		System.out.println("second:"+secList);
		return "front/top";
	}
	@RequestMapping("/index")
	public String index(Model model,HttpServletRequest request,HttpServletResponse response){

		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id order by sort asc ", 1);
		model.addAttribute("second", secList);
		
		List<IndexImg> imgs = imgService.getAllByProperty(" type=:type ", 1);
		model.addAttribute("lunbo", imgs);
		
		List<IndexImg> imgList = imgService.getAllByProperty(" type=:type ", 2);
		model.addAttribute("imglist", imgList);
		
		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		List<About> about =aboutService.getAllByProperty(" type=:type", "公司概况");
		
		for(int i = 0; i < about.size(); i++){
			if(about.get(i).getPublish() == 0){
				about.remove(i);
			}
		}
		int p=1;
		about=page.getInitPage(about,1,1);
		about=(ArrayList)page.getAppointPage(p);
		model.addAttribute("about", about);

		List<XinWen> xinwen =xinwenService.getAllByProperty(" 1=:id order by time desc", 1);
		for(int i = 0; i < xinwen.size(); i++){
			if(xinwen.get(i).getPublish() == 0){
				xinwen.remove(i);
			}
		}
		xinwen=page.getInitPage(xinwen,1,4);
		xinwen=(ArrayList)page.getAppointPage(p);
		model.addAttribute("xinwen", xinwen);

		return "front/index";
	}
	@RequestMapping("/renli")
	public String renli(Model model,HttpServletRequest request,HttpServletResponse response){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id order by sort asc ", 1);
		model.addAttribute("second", secList);
		
		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		List<RenLi> huanyingci =renliService.getAllByProperty(" type=:type", "欢迎辞");
		for(int i = 0; i < huanyingci.size(); i++){
			if(huanyingci.get(i).getPublish() == 0){
				huanyingci.remove(i);
			}
		}
		int p = 1;
		huanyingci=page.getInitPage(huanyingci,1,6);
		huanyingci=(ArrayList)page.getAppointPage(p);
		model.addAttribute("one", huanyingci);

		List<RenLi> zhanlue =renliService.getAllByProperty(" type=:type", "人才战略");
		for(int i = 0; i < zhanlue.size(); i++){
			if(zhanlue.get(i).getPublish() == 0){
				zhanlue.remove(i);
			}
		}
		zhanlue=page.getInitPage(zhanlue,1,8);
		zhanlue=(ArrayList)page.getAppointPage(p);
		model.addAttribute("two", zhanlue);

		List<RenLi> jizhi =renliService.getAllByProperty(" type=:type", "人才机制");
		for(int i = 0; i < jizhi.size(); i++){
			if(jizhi.get(i).getPublish() == 0){
				jizhi.remove(i);
			}
		}
		jizhi=page.getInitPage(jizhi,1,6);
		jizhi=(ArrayList)page.getAppointPage(p);
		model.addAttribute("three", jizhi);

		List<ZhaoPin> trans =zhaoPinService.getAllByProperty(" 1=:id  order by time desc", 1);
		for(int i = 0; i < trans.size(); i++){
			if(trans.get(i).getPublish() == 0){
				trans.remove(i);
			}
		}
		trans=page.getInitPage(trans,1,6);
		trans=(ArrayList)page.getAppointPage(p);
		model.addAttribute("four", trans);
		
		List<RenLi> all =renliService.getEntityAll();
		model.addAttribute("all", all);
		
		return "front/renliziyuan";

	}
	@RequestMapping("/rllist")
	public String renlilist(Model model,HttpServletRequest request,HttpServletResponse response){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id order by sort asc ", 1);
		model.addAttribute("second", secList);
		
		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		
		String type = (String) request.getParameter("type");
		List<RenLi> huanyingci =renliService.getAllByProperty(" type=:type", "欢迎辞");
		for(int i = 0; i < huanyingci.size(); i++){
			if(huanyingci.get(i).getPublish() == 0){
				huanyingci.remove(i);
			}
		}
		int p = 1;
		huanyingci=page.getInitPage(huanyingci,1,6);
		huanyingci=(ArrayList)page.getAppointPage(p);
		model.addAttribute("one", huanyingci);

		List<RenLi> zhanlue =renliService.getAllByProperty(" type=:type", "人才战略");
		for(int i = 0; i < zhanlue.size(); i++){
			if(zhanlue.get(i).getPublish() == 0){
				zhanlue.remove(i);
			}
		}
		zhanlue=page.getInitPage(zhanlue,1,8);
		zhanlue=(ArrayList)page.getAppointPage(p);
		model.addAttribute("two", zhanlue);

		List<RenLi> jizhi =renliService.getAllByProperty(" type=:type", "人才机制");
		for(int i = 0; i < jizhi.size(); i++){
			if(jizhi.get(i).getPublish() == 0){
				jizhi.remove(i);
			}
		}
		jizhi=page.getInitPage(jizhi,1,6);
		jizhi=(ArrayList)page.getAppointPage(p);
		model.addAttribute("three", jizhi);

		List<ZhaoPin> trans =zhaoPinService.getAllByProperty(" 1=:id  order by time desc", 1);
		for(int i = 0; i < trans.size(); i++){
			if(trans.get(i).getPublish() == 0){
				trans.remove(i);
			}
		}
		trans=page.getInitPage(trans,1,6);
		trans=(ArrayList)page.getAppointPage(p);
		model.addAttribute("four", trans);
		if(("2").equals(type)){
			return "front/zhanlue";
		}else if(("3").equals(type)){
			return "front/jizhi";
		}else if(("4").equals(type)){
			return "front/zhaopin";
		}else if(("1").equals(type)){
			return "front/renliziyuan";
		}else {
			return "redirect:renli";
		}

	}
	@RequestMapping("/rlinfo")
	public String renliinfo(Model model,HttpServletRequest request,HttpServletResponse response){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id order by sort asc ", 1);
		model.addAttribute("second", secList);

		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		Integer id=Integer.parseInt(request.getParameter("id")); 
		ZhaoPin trans= zhaoPinService.getEntityByProperty(" id=:id ", id);
		model.addAttribute("trans", trans);
		return "front/transdetail";

	}
	
	@RequestMapping("/guanyu")
	public String guanyu(Model model,HttpServletRequest request,HttpServletResponse response){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id order by sort asc ", 1);
		model.addAttribute("second", secList);

		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		List<About> gaikuang =aboutService.getAllByProperty(" type=:type", "公司概况");
		for(int i = 0; i < gaikuang.size(); i++){
			if(gaikuang.get(i).getPublish() == 0){
				gaikuang.remove(i);
			}
		}
		int p = 1;
		gaikuang=page.getInitPage(gaikuang,1,6);
		gaikuang=(ArrayList)page.getAppointPage(p);
		model.addAttribute("one", gaikuang);

		List<About> zhanlue =aboutService.getAllByProperty(" type=:type", "分支机构");
		for(int i = 0; i < zhanlue.size(); i++){
			if(zhanlue.get(i).getPublish() == 0){
				zhanlue.remove(i);
			}
		}
		zhanlue=page.getInitPage(zhanlue,1,8);
		zhanlue=(ArrayList)page.getAppointPage(p);
		model.addAttribute("two", zhanlue);

		List<Honor> jizhi =honorService.getAllByProperty(" 1=:id ", 1);
		for(int i = 0; i < jizhi.size(); i++){
			if(jizhi.get(i).getPublish() == 0){
				jizhi.remove(i);
			}
		}
		jizhi=page.getInitPage(jizhi,1,18);
		jizhi=(ArrayList)page.getAppointPage(p);
		model.addAttribute("three", jizhi);

		List<About> trans =aboutService.getAllByProperty(" type=:type", "公司大事记");
		for(int i = 0; i < trans.size(); i++){
			if(trans.get(i).getPublish() == 0){
				trans.remove(i);
			}
		}
		trans=page.getInitPage(trans,1,6);
		trans=(ArrayList)page.getAppointPage(p);
		model.addAttribute("four", trans);
		return "front/guanyu";

	}
	
	@RequestMapping("/gylist")
	public String guanyulist(Model model,HttpServletRequest request,HttpServletResponse response){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id order by sort asc ", 1);
		model.addAttribute("second", secList);

		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		String type = (String) request.getParameter("type");
		List<About> gaikuang =aboutService.getAllByProperty(" type=:type", "公司概况");
		for(int i = 0; i < gaikuang.size(); i++){
			if(gaikuang.get(i).getPublish() == 0){
				gaikuang.remove(i);
			}
		}
		int p = 1;
		gaikuang=page.getInitPage(gaikuang,1,6);
		gaikuang=(ArrayList)page.getAppointPage(p);
		model.addAttribute("one", gaikuang);

		List<About> zhanlue =aboutService.getAllByProperty(" type=:type", "分支机构");
		for(int i = 0; i < zhanlue.size(); i++){
			if(zhanlue.get(i).getPublish() == 0){
				zhanlue.remove(i);
			}
		}
		zhanlue=page.getInitPage(zhanlue,1,8);
		zhanlue=(ArrayList)page.getAppointPage(p);
		model.addAttribute("two", zhanlue);

		List<Honor> jizhi =honorService.getAllByProperty(" 1=:id", 1);
		for(int i = 0; i < jizhi.size(); i++){
			if(jizhi.get(i).getPublish() == 0){
				jizhi.remove(i);
			}
		}
		jizhi=page.getInitPage(jizhi,1,18);
		jizhi=(ArrayList)page.getAppointPage(p);
		model.addAttribute("three", jizhi);

		List<About> trans =aboutService.getAllByProperty(" type=:type", "公司大事记");
		for(int i = 0; i < trans.size(); i++){
			if(trans.get(i).getPublish() == 0){
				trans.remove(i);
			}
		}
		trans=page.getInitPage(trans,1,6);
		trans=(ArrayList)page.getAppointPage(p);
		model.addAttribute("four", trans);
		if(("2").equals(type)){
			return "front/jigou";
		}else if(("3").equals(type)){
			return "front/honor";
		}else if(("4").equals(type)){
			return "front/dashiji";
		}else if(("1").equals(type)){
			return "front/guanyu";
		}else {
			return "redirect:renli";
		}

	}
	
	@RequestMapping("/gyinfo")
	public String guanyuinfo(Model model,HttpServletRequest request,HttpServletResponse response){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id order by sort asc ", 1);
		model.addAttribute("second", secList);

		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		Integer id=Integer.parseInt(request.getParameter("id")); 
		About trans= aboutService.getEntityByProperty(" id=:id ", id);
		model.addAttribute("xw", trans);
		return "front/guanyudetail";

	}
	
	@RequestMapping("/xinwen")
	public String xinwen(Model model,HttpServletRequest request,HttpServletResponse response){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id order by sort asc ", 1);
		model.addAttribute("second", secList);

		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		List<XinWen> fengCai =xinwenService.getAllByProperty(" 1=:id  order by time desc", 1);
		for(int i = 0; i < fengCai.size(); i++){
			if(fengCai.get(i).getPublish() == 0){
				fengCai.remove(i);
			}
		}
		int p = 1;
		fengCai=page.getInitPage(fengCai,1,18);
		fengCai=(ArrayList)page.getAppointPage(p);
		model.addAttribute("one", fengCai);
		return "front/qiyexinwen";

	}
	
	@RequestMapping("/xwinfo")
	public String xinweninfo(Model model,HttpServletRequest request,HttpServletResponse response){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id ", 1);
		model.addAttribute("second", secList);

		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		Integer id=Integer.parseInt(request.getParameter("id")); 
		XinWen trans= xinwenService.getEntityByProperty(" id=:id ", id);
		model.addAttribute("xw", trans);
		return "front/xinwendetail";

	}
	
	@RequestMapping("/chanpin")
	public String chanpin(Model model,HttpServletRequest request,HttpServletResponse response){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id ", 1);
		model.addAttribute("second", secList);

		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		List<CaseList> gaikuang =caseListService.getAllByProperty(" type=:type", "油气勘探生产");
		for(int i = 0; i < gaikuang.size(); i++){
			if(gaikuang.get(i).getPublish() == 0){
				gaikuang.remove(i);
			}
		}
		int p = 1;
		gaikuang=page.getInitPage(gaikuang,1,6);
		gaikuang=(ArrayList)page.getAppointPage(p);
		model.addAttribute("one", gaikuang);

		List<CaseList> zhanlue =caseListService.getAllByProperty(" type=:type", "多相计量产品与服务");
		for(int i = 0; i < zhanlue.size(); i++){
			if(zhanlue.get(i).getPublish() == 0){
				zhanlue.remove(i);
			}
		}
		zhanlue=page.getInitPage(zhanlue,1,8);
		zhanlue=(ArrayList)page.getAppointPage(p);
		model.addAttribute("two", zhanlue);

		List<CaseList> jizhi =caseListService.getAllByProperty(" type=:type", "压裂设备与服务");
		for(int i = 0; i < jizhi.size(); i++){
			if(jizhi.get(i).getPublish() == 0){
				jizhi.remove(i);
			}
		}
		jizhi=page.getInitPage(jizhi,1,6);
		jizhi=(ArrayList)page.getAppointPage(p);
		model.addAttribute("three", jizhi);

		List<CaseList> trans =caseListService.getAllByProperty(" type=:type", "环保设备与服务");
		for(int i = 0; i < trans.size(); i++){
			if(trans.get(i).getPublish() == 0){
				trans.remove(i);
			}
		}
		trans=page.getInitPage(trans,1,6);
		trans=(ArrayList)page.getAppointPage(p);
		model.addAttribute("four", trans);
		return "front/chanpinfuwu";

	}
	
	@RequestMapping("/cplist")
	public String chanpinlist(Model model,HttpServletRequest request,HttpServletResponse response){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id order by sort asc ", 1);
		model.addAttribute("second", secList);

		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		String type = (String) request.getParameter("type");
		List<CaseList> gaikuang =caseListService.getAllByProperty(" type=:type", "油气勘探生产");
		for(int i = 0; i < gaikuang.size(); i++){
			if(gaikuang.get(i).getPublish() == 0){
				gaikuang.remove(i);
			}
		}
		int p = 1;
		gaikuang=page.getInitPage(gaikuang,1,6);
		gaikuang=(ArrayList)page.getAppointPage(p);
		model.addAttribute("one", gaikuang);

		List<CaseList> zhanlue =caseListService.getAllByProperty(" type=:type", "多相计量产品与服务");
		for(int i = 0; i < zhanlue.size(); i++){
			if(zhanlue.get(i).getPublish() == 0){
				zhanlue.remove(i);
			}
		}
		zhanlue=page.getInitPage(zhanlue,1,8);
		zhanlue=(ArrayList)page.getAppointPage(p);
		model.addAttribute("two", zhanlue);

		List<CaseList> jizhi =caseListService.getAllByProperty(" type=:type", "压裂设备与服务");
		for(int i = 0; i < jizhi.size(); i++){
			if(jizhi.get(i).getPublish() == 0){
				jizhi.remove(i);
			}
		}
		jizhi=page.getInitPage(jizhi,1,6);
		jizhi=(ArrayList)page.getAppointPage(p);
		model.addAttribute("three", jizhi);

		List<CaseList> trans =caseListService.getAllByProperty(" type=:type", "环保设备与服务");
		for(int i = 0; i < trans.size(); i++){
			if(trans.get(i).getPublish() == 0){
				trans.remove(i);
			}
		}
		trans=page.getInitPage(trans,1,6);
		trans=(ArrayList)page.getAppointPage(p);
		model.addAttribute("four", trans);
		if(("2").equals(type)){
			return "front/duoxiang";
		}else if(("3").equals(type)){
			return "front/yalie";
		}else if(("4").equals(type)){
			return "front/huanbao";
		}else if(("1").equals(type)){
			return "front/chanpinfuwu";
		}else {
			return "redirect:chanpin";
		}

	}
	
	@RequestMapping("cpinfo")
	public String chanpininfo(Model model,HttpServletRequest request,HttpServletResponse response){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id ", 1);
		model.addAttribute("second", secList);

		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		Integer id=Integer.parseInt(request.getParameter("id")); 
		CaseList trans= caseListService.getEntityByProperty(" id=:id ", id);
		model.addAttribute("xw", trans);
		return "front/chanpindetail";

	}
	
	@RequestMapping("/jishu")
	public String jishu(Model model,HttpServletRequest request,HttpServletResponse response){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id order by sort asc ", 1);
		model.addAttribute("second", secList);

		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		List<JiShu> gaikuang =jiShuService.getAllByProperty(" type=:type", "科研机构");
		for(int i = 0; i < gaikuang.size(); i++){
			if(gaikuang.get(i).getPublish() == 0){
				gaikuang.remove(i);
			}
		}
		int p = 1;
		gaikuang=page.getInitPage(gaikuang,1,6);
		gaikuang=(ArrayList)page.getAppointPage(p);
		model.addAttribute("one", gaikuang);

		List<JiShu> zhanlue =jiShuService.getAllByProperty(" type=:type", "科研成果");
		for(int i = 0; i < zhanlue.size(); i++){
			if(zhanlue.get(i).getPublish() == 0){
				zhanlue.remove(i);
			}
		}
		zhanlue=page.getInitPage(zhanlue,1,8);
		zhanlue=(ArrayList)page.getAppointPage(p);
		model.addAttribute("two", zhanlue);

		List<JiShu> jizhi =jiShuService.getAllByProperty(" type=:type", "研发动态");
		for(int i = 0; i < jizhi.size(); i++){
			if(jizhi.get(i).getPublish() == 0){
				jizhi.remove(i);
			}
		}
		jizhi=page.getInitPage(jizhi,1,6);
		jizhi=(ArrayList)page.getAppointPage(p);
		model.addAttribute("three", jizhi);

		List<JiShu> trans =jiShuService.getAllByProperty(" type=:type", "典型案例");
		for(int i = 0; i < trans.size(); i++){
			if(trans.get(i).getPublish() == 0){
				trans.remove(i);
			}
		}
		trans=page.getInitPage(trans,1,6);
		trans=(ArrayList)page.getAppointPage(p);
		model.addAttribute("four", trans);
		return "front/jishujiaoliu";

	}
	
	@RequestMapping("/jslist")
	public String jishulist(Model model,HttpServletRequest request,HttpServletResponse response){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id order by sort asc ", 1);
		model.addAttribute("second", secList);

		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		String type = (String) request.getParameter("type");
		List<JiShu> gaikuang =jiShuService.getAllByProperty(" type=:type", "科研机构");
		for(int i = 0; i < gaikuang.size(); i++){
			if(gaikuang.get(i).getPublish() == 0){
				gaikuang.remove(i);
			}
		}
		int p = 1;
		gaikuang=page.getInitPage(gaikuang,1,6);
		gaikuang=(ArrayList)page.getAppointPage(p);
		model.addAttribute("one", gaikuang);

		List<JiShu> zhanlue =jiShuService.getAllByProperty(" type=:type", "科研成果");
		for(int i = 0; i < zhanlue.size(); i++){
			if(zhanlue.get(i).getPublish() == 0){
				zhanlue.remove(i);
			}
		}
		zhanlue=page.getInitPage(zhanlue,1,8);
		zhanlue=(ArrayList)page.getAppointPage(p);
		model.addAttribute("two", zhanlue);

		List<JiShu> jizhi =jiShuService.getAllByProperty(" type=:type", "研发动态");
		for(int i = 0; i < jizhi.size(); i++){
			if(jizhi.get(i).getPublish() == 0){
				jizhi.remove(i);
			}
		}
		jizhi=page.getInitPage(jizhi,1,6);
		jizhi=(ArrayList)page.getAppointPage(p);
		model.addAttribute("three", jizhi);

		List<JiShu> trans =jiShuService.getAllByProperty(" type=:type", "典型案例");
		for(int i = 0; i < trans.size(); i++){
			if(trans.get(i).getPublish() == 0){
				trans.remove(i);
			}
		}
		trans=page.getInitPage(trans,1,6);
		trans=(ArrayList)page.getAppointPage(p);
		model.addAttribute("four", trans);
		if(("2").equals(type)){
			return "front/chengguo";
		}else if(("3").equals(type)){
			return "front/dongtai";
		}else if(("4").equals(type)){
			return "front/anli";
		}else if(("1").equals(type)){
			return "front/jishujiaoliu";
		}else {
			return "redirect:jishu";
		}

	}
	
	@RequestMapping("jsinfo")
	public String jishuinfo(Model model,HttpServletRequest request,HttpServletResponse response){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id order by sort asc ", 1);
		model.addAttribute("second", secList);

		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		Integer id=Integer.parseInt(request.getParameter("id")); 
		JiShu trans= jiShuService.getEntityByProperty(" id=:id ", id);
		model.addAttribute("xw", trans);
		return "front/jishudetail";

	}
	
	@RequestMapping("/touzi")
	public String touzi(Model model,HttpServletRequest request,HttpServletResponse response){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id ", 1);
		model.addAttribute("second", secList);

		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		List<TouZhi> gaikuang =touZhiService.getAllByProperty(" type=:type", "基本资料");
		for(int i = 0; i < gaikuang.size(); i++){
			if(gaikuang.get(i).getPublish() == 0){
				gaikuang.remove(i);
			}
		}
		int p = 1;
		gaikuang=page.getInitPage(gaikuang,1,6);
		gaikuang=(ArrayList)page.getAppointPage(p);
		model.addAttribute("one", gaikuang);

		List<TouZhi> zhanlue =touZhiService.getAllByProperty(" type=:type", "公司治理机构");
		for(int i = 0; i < zhanlue.size(); i++){
			if(zhanlue.get(i).getPublish() == 0){
				zhanlue.remove(i);
			}
		}
		zhanlue=page.getInitPage(zhanlue,1,8);
		zhanlue=(ArrayList)page.getAppointPage(p);
		model.addAttribute("two", zhanlue);

		List<TouZhi> jizhi =touZhiService.getAllByProperty(" type=:type", "公司利润分配情况");
		for(int i = 0; i < jizhi.size(); i++){
			if(jizhi.get(i).getPublish() == 0){
				jizhi.remove(i);
			}
		}
		jizhi=page.getInitPage(jizhi,1,6);
		jizhi=(ArrayList)page.getAppointPage(p);
		model.addAttribute("three", jizhi);

		List<TouZhi> trans =touZhiService.getAllByProperty(" type=:type", "公司公告");
		for(int i = 0; i < trans.size(); i++){
			if(trans.get(i).getPublish() == 0){
				trans.remove(i);
			}
		}
		trans=page.getInitPage(trans,1,6);
		trans=(ArrayList)page.getAppointPage(p);
		model.addAttribute("four", trans);
		
		List<TouZhi> jiaoliu =touZhiService.getAllByProperty(" type=:type", "投资者交流");
		for(int i = 0; i < jiaoliu.size(); i++){
			if(jiaoliu.get(i).getPublish() == 0){
				jiaoliu.remove(i);
			}
		}
		jiaoliu=page.getInitPage(jiaoliu,1,6);
		jiaoliu=(ArrayList)page.getAppointPage(p);
		model.addAttribute("five", jiaoliu);
		
		return "front/touzizhe";

	}
	
	@RequestMapping("/tzlist")
	public String touzilist(Model model,HttpServletRequest request,HttpServletResponse response){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id ", 1);
		model.addAttribute("second", secList);

		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		String type = (String) request.getParameter("type");
		List<TouZhi> gaikuang =touZhiService.getAllByProperty(" type=:type", "基本资料");
		for(int i = 0; i < gaikuang.size(); i++){
			if(gaikuang.get(i).getPublish() == 0){
				gaikuang.remove(i);
			}
		}
		int p = 1;
		gaikuang=page.getInitPage(gaikuang,1,6);
		gaikuang=(ArrayList)page.getAppointPage(p);
		model.addAttribute("one", gaikuang);

		List<TouZhi> zhanlue =touZhiService.getAllByProperty(" type=:type", "公司治理机构");
		for(int i = 0; i < zhanlue.size(); i++){
			if(zhanlue.get(i).getPublish() == 0){
				zhanlue.remove(i);
			}
		}
		zhanlue=page.getInitPage(zhanlue,1,8);
		zhanlue=(ArrayList)page.getAppointPage(p);
		model.addAttribute("two", zhanlue);

		List<TouZhi> jizhi =touZhiService.getAllByProperty(" type=:type", "公司利润分配情况");
		for(int i = 0; i < jizhi.size(); i++){
			if(jizhi.get(i).getPublish() == 0){
				jizhi.remove(i);
			}
		}
		jizhi=page.getInitPage(jizhi,1,6);
		jizhi=(ArrayList)page.getAppointPage(p);
		model.addAttribute("three", jizhi);

		List<TouZhi> trans =touZhiService.getAllByProperty(" type=:type", "公司公告");
		for(int i = 0; i < trans.size(); i++){
			if(trans.get(i).getPublish() == 0){
				trans.remove(i);
			}
		}
		trans=page.getInitPage(trans,1,6);
		trans=(ArrayList)page.getAppointPage(p);
		model.addAttribute("four", trans);
		
		List<TouZhi> jiaoliu =touZhiService.getAllByProperty(" type=:type", "投资者交流");
		for(int i = 0; i < jiaoliu.size(); i++){
			if(jiaoliu.get(i).getPublish() == 0){
				jiaoliu.remove(i);
			}
		}
		jiaoliu=page.getInitPage(jiaoliu,1,6);
		jiaoliu=(ArrayList)page.getAppointPage(p);
		model.addAttribute("five", jiaoliu);
		if(("2").equals(type)){
			return "front/zhili";
		}else if(("3").equals(type)){
			return "front/fenpei";
		}else if(("4").equals(type)){
			return "front/gonggao";
		}else if(("5").equals(type)){
			return "front/jiaoliu";
		}else if(("1").equals(type)){
			return "front/touzizhe";
		}else {
			return "redirect:touzi";
		}

	}
	
	@RequestMapping("/tzinfo")
	public String touziinfo(Model model,HttpServletRequest request,HttpServletResponse response){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id order by sort asc ", 1);
		model.addAttribute("second", secList);

		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		Integer id=Integer.parseInt(request.getParameter("id")); 
		TouZhi trans= touZhiService.getEntityByProperty(" id=:id ", id);
		model.addAttribute("xw", trans);
		return "front/touzidetail";

	}
	
	@RequestMapping("/addxq")
	public String addxuqiu(Model model,HttpServletRequest request,HttpServletResponse response,XuQiu gaiKuo){
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		String time = df.format(new Date());
		gaiKuo.setContent(WebUtil.TFUFT8(gaiKuo.getContent()));
		gaiKuo.setName(WebUtil.TFUFT8(gaiKuo.getName()));
		gaiKuo.setPhone(WebUtil.TFUFT8(gaiKuo.getPhone()));
		gaiKuo.setTime(WebUtil.TFUFT8(time));
		xuQiuService.addEntity(gaiKuo);
		return "redirect:index";
	}
	
	@RequestMapping("/xiazai1")
	public String xiazai(Model model,HttpServletRequest request,HttpServletResponse response){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id order by sort asc ", 1);
		model.addAttribute("second", secList);

		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		List<XiaZai> gaikuang =xiaZaiService.getAllByProperty(" type=:type", "技术文献");
		for(int i = 0; i < gaikuang.size(); i++){
			if(gaikuang.get(i).getPublish() == 0){
				gaikuang.remove(i);
			}
		}
		int p = 1;
		gaikuang=page.getInitPage(gaikuang,1,6);
		gaikuang=(ArrayList)page.getAppointPage(p);
		model.addAttribute("one", gaikuang);

		List<XiaZai> zhanlue =xiaZaiService.getAllByProperty(" type=:type", "参考资料");
		for(int i = 0; i < zhanlue.size(); i++){
			if(zhanlue.get(i).getPublish() == 0){
				zhanlue.remove(i);
			}
		}
		zhanlue=page.getInitPage(zhanlue,1,8);
		zhanlue=(ArrayList)page.getAppointPage(p);
		model.addAttribute("two", zhanlue);

		List<XiaZai> jizhi =xiaZaiService.getAllByProperty(" type=:type", "产品手册");
		for(int i = 0; i < jizhi.size(); i++){
			if(jizhi.get(i).getPublish() == 0){
				jizhi.remove(i);
			}
		}
		jizhi=page.getInitPage(jizhi,1,6);
		jizhi=(ArrayList)page.getAppointPage(p);
		model.addAttribute("three", jizhi);
		return "front/xiazaizhongxin";
	}
	
	@RequestMapping("/xzlist")
	public String xiazailist(Model model,HttpServletRequest request,HttpServletResponse response){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id order by sort asc ", 1);
		model.addAttribute("second", secList);

		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		String type = request.getParameter("type");
		List<XiaZai> gaikuang =xiaZaiService.getAllByProperty(" type=:type", "技术文献");
		for(int i = 0; i < gaikuang.size(); i++){
			if(gaikuang.get(i).getPublish() == 0){
				gaikuang.remove(i);
			}
		}
		int p = 1;
		gaikuang=page.getInitPage(gaikuang,1,6);
		gaikuang=(ArrayList)page.getAppointPage(p);
		model.addAttribute("one", gaikuang);

		List<XiaZai> zhanlue =xiaZaiService.getAllByProperty(" type=:type", "参考资料");
		for(int i = 0; i < zhanlue.size(); i++){
			if(zhanlue.get(i).getPublish() == 0){
				zhanlue.remove(i);
			}
		}
		zhanlue=page.getInitPage(zhanlue,1,8);
		zhanlue=(ArrayList)page.getAppointPage(p);
		model.addAttribute("two", zhanlue);

		List<XiaZai> jizhi =xiaZaiService.getAllByProperty(" type=:type", "产品手册");
		for(int i = 0; i < jizhi.size(); i++){
			if(jizhi.get(i).getPublish() == 0){
				jizhi.remove(i);
			}
		}
		jizhi=page.getInitPage(jizhi,1,6);
		jizhi=(ArrayList)page.getAppointPage(p);
		model.addAttribute("three", jizhi);
		if(("2").equals(type)){
			return "front/ziliao";
		}else if(("3").equals(type)){
			return "front/shouce";
		}else if(("1").equals(type)){
			return "front/xiazaizhongxin";
		}else {
			return "redirect:index";
		}
	}
	
	@RequestMapping("/goapp")
	public String gohuiyuan(Model model,HttpServletRequest request,HttpServletResponse response){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id order by sort asc ", 1);
		model.addAttribute("second", secList);

		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		String id = request.getParameter("id");
		model.addAttribute("id", id);
		return "front/application";
	}
	
	@RequestMapping("/app")
	public String addapp(Model model,HttpServletRequest request,HttpServletResponse response,Application application){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id order by sort asc ", 1);
		model.addAttribute("second", secList);

		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);

		String id = request.getParameter("id");
		ZhaoPin pin = zhaoPinService.getEntityByProperty(" id=:id ", Integer.parseInt(id));
		
		application.setName(WebUtil.TFUFT8(application.getName()));
		application.setPhone(WebUtil.TFUFT8(application.getPhone()));
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		String time = df.format(new Date());
		application.setTime(WebUtil.TFUFT8(time));
		application.setAchadr(WebUtil.TFUFT8(application.getAchadr()));
		application.setAdress(WebUtil.TFUFT8(application.getAdress()));
		application.setAge(WebUtil.TFUFT8(application.getAge()));
		application.setCompany(WebUtil.TFUFT8(application.getCompany()));
		application.setEmail(WebUtil.TFUFT8(application.getEmail()));
		application.setHy(WebUtil.TFUFT8(application.getHy()));
		application.setJineng(WebUtil.TFUFT8(application.getJineng()));
		application.setMoney(WebUtil.TFUFT8(application.getMoney()));
		application.setQwhy(WebUtil.TFUFT8(application.getQwhy()));
		application.setSchool(WebUtil.TFUFT8(application.getSchool()));
		application.setZy(WebUtil.TFUFT8(application.getZy()));
		application.setTranslation(pin);
		appService.addEntity(application);
		return "redirect:rlinfo?id="+id;
	}
	@RequestMapping(value="xiazai")
    public String list(Model model,HttpServletRequest request){
		
		List<Title> title = titleService.getAllByProperty(" 1=:id order by sort asc", 1);
		model.addAttribute("first", title);
		
		List<SecondTitle> secList = secondTitleService.getAllByProperty(" 1=:id order by sort asc ", 1);
		model.addAttribute("second", secList);

		List<IndexImg> contact = imgService.getAllByProperty(" type=:type ", 3);
		model.addAttribute("contact", contact);
		
		List<XiaZai> list = xiaZaiService.getAllByProperty(" 1=:id order by time desc", 1);
    	model.addAttribute("list",  list);
    	WebUtil.init(request);
        request.setAttribute("one",  WebUtil.getMap());
        model.addAttribute("one",  WebUtil.getMap());
        return "front/xiazaizhongxin";
    }
	
	@RequestMapping(value="download")
    public void download(HttpServletRequest request, HttpServletResponse response){
        WebUtil.init(request);
        try {
            String downloadfFileName = request.getParameter("filename");
            downloadfFileName = new String(downloadfFileName.getBytes("iso-8859-1"),"utf-8");
            String fileName = downloadfFileName.substring(downloadfFileName.indexOf("_")+1);
            String userAgent = request.getHeader("User-Agent");
            byte[] bytes = userAgent.contains("MSIE") ? fileName.getBytes() : fileName.getBytes("UTF-8"); 
            fileName = new String(bytes, "ISO-8859-1");
            response.setHeader("Content-disposition", String.format("attachment; filename=\"%s\"", fileName));
            WebUtil.download(downloadfFileName, response.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
